<?php use_javascript('/js/fancybox/jquery.fancybox-1.3.4.js') ?>
<?php use_stylesheet('/js/fancybox/jquery.fancybox-1.3.4.css') ?>
<?php $objDef = new objectDef('mesdossiers');
   	$actualnbPosts = $config['nbResults'];
   	$actualOrder = $config['orderColumn'];
	$hide = $config['hide'];
	if(!isset($hide)) $hide = array();
	$functionParams = '\''.$view.'\','.$actualTab.','.$actualPage.','.$actualnbPosts;
?>
<script type="text/javascript">
	function hideandshowRef(name)
	{	
		if(document.getElementById(name).style.display == "none")
		{
			document.getElementById(name).style.display = "block";
		}
		else
		{
			document.getElementById(name).style.display = "none";
		}
	}


	function refresh(view, tabID, page, nbPosts, orderField){
		document.getElementById('updateView').style.display = 'block';
		for (i=0; i<= <?php echo count($tabs) - 1?>; i++) {
			nomLabel = 'tabs-label-'+i;
			if(i==tabID){
				document.getElementById(nomLabel).style.backgroundColor = "white";
			}else{
				document.getElementById(nomLabel).style.backgroundColor = "#D0E3FA";
			}
		}
		//var ancienClassName = document.getElementById('listeDemandes').className;
		//document.getElementById('listeDemandes').className = ancienClassName + ' working';
		$('#listeDemandes').fadeTo("fast", 0.5);
		
		getXmlHttpRequest();
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200)
				{
				textResponse = xhr.responseText;
				document.getElementById('updateView').style.display = 'none';
				document.getElementById('listeDemandes').innerHTML = textResponse;
				$("a.dmdPreview").fancybox({
						'transitionIn'	:	'elastic',
						'transitionOut'	:	'elastic',
						'speedIn'		:	600, 
						'speedOut'		:	200, 
						'overlayShow'	:	false,
						'titleShow'		: false
					});
				$('#listeDemandes').fadeTo("fast",1);
				
			}
		};
		xhr.open("POST","<?php print url_for('mesdossiers/renderList'); ?>",true);
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("view="+view+"&page="+page+"&tab="+tabID+"&nbPosts="+nbPosts+"&order="+orderField);
		document.getElementById('refreshFunctionParams').value = '\''+view+'\','+tabID+',1,'+nbPosts;
	
	}
	
	function showTab(tabId)
	{	
		getXmlHttpRequest();
		
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200)
			{
				myRoute = xhr.responseText;
				for (i=1; i<= <?php echo count($tabs)?>; i++) {
					nomTab = 'tabs-'+i;
					nomLabel = 'tabs-label-'+i;
					if(i==tabId){
						document.getElementById(nomTab).style.display = "block";
						document.getElementById(nomLabel).style.backgroundColor = "white";
						document.getElementById('refreshFunctionParams').value = "<?php echo '\''.$view.'\','?>" + tabId+ ",1,<?php echo $actualnbPosts?>";
					}else{
						document.getElementById(nomTab).style.display = "none";
						document.getElementById(nomLabel).style.backgroundColor = "#D0E3FA";
					}
				}
			}
		}
		xhr.open("POST","<?php print url_for('mesdossiers/setTab'); ?>",true) ;
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xhr.send("tab="+tabId);
	}

</script>
<?php include_partial('search/searchBar',array( 'moduleRef' => $moduleRef, 'actionRef' => $action, 'className'=>'mesdossiers', 'ajaxSearch'=>true))?>
<?php $routeName = sfContext::getInstance()->getRouting()->getCurrentInternalUri(false) ?>
<input type="hidden" id="refreshFunctionParams" name="refreshFunctionParams" value="<?php echo '\''.$view.'\','.$actualTab.','.$actualPage.','.$actualnbPosts.',\'\'';?>,''"></input>

	<?php if ($sf_user->hasFlash('warning')): ?>
	<div id="warning" class="errorDisplay" style = "display:block;">
		<h3><?php print $sf_user->getFlash('warning'); ?></h3>
	</div>
<?php endif;?>
<?php if ($sf_user->hasFlash('userMsg')): ?>
	<div id="userMsg" class="msgDisplay" style="display: block;">
		<h3><?php print $sf_user->getFlash('userMsg'); ?></h3>
	</div>
<?php endif;?>
<br />

<div id="tabs">
	<ul class="tabs">
		<?php
			foreach($tabs as $key => $config)
			{
				if($actualTab==$key){
					$backGround = 'white';
					$page = $actualPage;
				}else{
					$backGround = '#D0E3FA';
					$page = 1;
				}
				$link = '<a href="javascript:refresh(\''.$view.'\','.$key.','.$page.','.$actualnbPosts.',\'\');">'.__($config['description']).'</a>';
		?>
				<li id="tabs-label-<?php echo $key;?>" style="background-color:<?php echo $backGround;?>"><?php echo $link;?></li>
		<?php
			}
		?>
	</ul>
	<div id="updateView" style="display:none;text-align:center;">
	<img alt="<?php echo __('wait please...')?> '" src="/images/ajax-loader.gif">
	</div>	
	<div style="width: 100%; height: 40px;"></div>
	<div id="listeDemandes">
	<?php $html .= '<table>'; // class="flexme2"
		$html .= $objDef->renderListHeader($hide,'table',false,true,$functionParams);
		$html .= "<tbody id=tableContent />";
		$html .= "</table>";
		echo $html;
		?>
	</div>
	
	<?php $defaultOrderCol = 'datedemande*desc';;
		  echo '<div style="margin-top:7px;"><a href="javascript: refresh(\''.$view.'\','.$actualTab.',1, '.sfConfig::get('app_posts_number_per_page', 10).',\''.$defaultOrderCol.'\' );">'.__('Restore view default values').'</a></div>';?>
</div>
<div id='dmdDetail'></div>
<script type="text/javascript">
$(document).ready(function(){
	addFilters();
});
	
</script>